package com.genius.util.Utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateHelper {

    public static String getToday() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        return formatter.format(currentTime);
    }

    public static String format( String szFmt ,Date date){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat( szFmt );
        return simpleDateFormat.format( date );
    }

    public static String format( String szFmt ,boolean bIsYesterDay){
        Date day = bIsYesterDay?new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24): new Date();
        return format(szFmt,day);
    }

    public static String formatYMD ( boolean bIsYesterDay ){
        return DateHelper.format( "yyyy-MM-dd",bIsYesterDay );
    }

    public static Date formatToDate(String szFmt,String time){
        if(szFmt==null||szFmt.equals("")){
            szFmt = "yyyy-MM-dd HH:mm:ss";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(szFmt);
        Date date = new Date();
        try {
            date = simpleDateFormat.parse(time);
        }catch (ParseException e){
            e.printStackTrace();
        }
        return date;

    }


    public static String formatYMDHMS ( boolean bIsYesterDay ){
        return DateHelper.format( "yyyy-MM-dd HH:mm:ss" ,bIsYesterDay);
    }


}




